#!/usr/bin/env ruby

LKP_SRC = ENV['LKP_SRC'] || File.dirname(File.dirname(File.realpath($PROGRAM_NAME)))

require "#{LKP_SRC}/lib/statistics"
require "#{LKP_SRC}/lib/log"
require "#{LKP_SRC}/lib/string_ext"

# skip none-result data
while (line = $stdin.gets)
  line = line.resolve_invalid_bytes
  break if line =~ /^FSUse/
end

files_per_sec = []
app_overhead = []

# FSUse%        Count         Size    Files/sec     App Overhead
#    12         3840     16777216          9.6        295550597
while (line = $stdin.gets)
  iteration = line.split
  break if iteration.size != 5

  files_per_sec << iteration[3].to_f
  app_overhead << iteration[4].to_f
end

# when result is empty, it's possible some kernel issue
# and it should not output meaningless stat like
# files_per_sec: '', instead it needs show nothing to
# become incompleted run
unless files_per_sec.empty?
  puts "files_per_sec: #{files_per_sec.average}"
  puts "app_overhead: #{app_overhead.average}"
end
